{extend name="layout/goods"/}
{block name="content"}
<!--主体-->
<header class="wy-header">
    <a href="javascript:history.back(-1);"><div class="wy-header-icon-back"><span></span></div></a>
    <div class="wy-header-title">订单详情</div>
</header>
<form id="pay-form" action="{:url('order/pay_goods')}" method="post">
    <div class="weui-content">
        <div class="wy-media-box weui-media-box_text address-select">
            <div class="weui-media-box_appmsg">
                {if condition="$address"}
                <div class="weui-media-box__hd proinfo-txt-l" style="width:20px;"><span class="promotion-label-tit"><img src="__CDN__/assets/img/icon_nav_city.png" /></span></div>
                <div class="weui-media-box__bd">
                    <a href="javascript:;" data-target="#select-address" class="weui-cell_access open-popup">
                        <h4 class="address-name"><span>{$address.consignee}</span><span>{$address.mobile}</span></h4>
                        <div class="address-txt">{$address.area}{$address.address}</div>
                    </a>
                </div>
                <div class="weui-media-box__hd proinfo-txt-l" style="width:16px;"><div class="weui-cell_access"><span class="weui-cell__ft"></span></div></div>
                <input type="hidden" name="address_id" value="{$address.id}" id="address_id">
                {else/}
                <div class="mg10-0 t-c">
                    您还没有收货地址，请 <a href="{:url('address/add')}">添加收货地址</a>
                </div>
                {/if}
            </div>
        </div>
        <div class="wy-media-box weui-media-box_text">
            <div class="weui-media-box__bd">
                <div class="weui-media-box_appmsg ord-pro-list">
                    <div class="weui-media-box__hd"><a href="{:url('goods/detail', ['id' => $goods['id']])}"><img class="weui-media-box__thumb" src="{$goods.cover}" alt=""></a></div>
                    <div class="weui-media-box__bd">
                        <h1 class="weui-media-box__desc"><a href="{:url('goods/detail', ['id' => $goods['id']])}" class="ord-pro-link">{$goods.name}</a></h1>
                        <!-- <p class="weui-media-box__desc">规格：<span>红色</span>，<span>23</span></p> -->
                        <div class="clear mg-t-10">
                            <div class="wy-pro-pri fl">¥<em class="num font-15">{$goods.price}</em></div>
                            <div class="pro-amount fr"><div id="spinner-amount" class="Spinner"></div></div>
                        </div>
                        <input type="hidden" name="goods_num" id="goods_num" value="1">
                        <input type="hidden" name="goods_id" id="goods_id" value="{$goods.id}">
                    </div>
                </div>
            </div>
        </div>
        <div class="weui-panel">
            <div class="weui-panel__bd">
                <div class="weui-media-box weui-media-box_small-appmsg">
                    <div class="weui-cells">
                        <div class="weui-cell weui-cell_access">
                            <div class="weui-cell__bd weui-cell_primary">
                                <p class="font-14"><span class="mg-r-10">配送方式</span><span class="fr">快递</span></p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="wy-media-box weui-media-box_text">
            <div class="mg10-0 t-c">总金额：<span class="wy-pro-pri mg-tb-5">¥<em class="num font-20" id="amountPrice">{$goods.price}</em></span></div>
            <div class="mg10-0"><a href="javascript:;" id="wechat-pay" class="weui-btn weui-btn_primary">微信付款</a></div>
        </div>
    </div>
</form>
<div id="select-address" class='weui-popup__container popup-bottom' style="z-index:600;">
    <div class="weui-popup__overlay" style="opacity:1;"></div>
    <div class="weui-popup__modal">
        <div class="modal-content" style="padding: 1rem .5rem;">
            <div class="weui-msg" style="padding-top:0;">
                {if condition="$addressList"}
                    {volist name="$addressList" id="v"}
                    <div class="address-list address-select-box">
                        <input type="radio" name="addres_id" value="{$v.id}" id="addres_id_{$v.id}">
                        <label for="addres_id_{$v.id}">
                            <a href="javascript:;" class="weui-cell_access address-info">
                                <h4 class="address-name"><span>{$v.consignee}</span><span>{$v.mobile}</span></h4>
                                <div class="address-txt">{$v.area}{$v.address}</div>
                            </a>
                        </label>
                    </div>
                    {/volist}
                {/if}
            </div>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script type="text/javascript" src="__CDN__/assets/js/jquery.Spinner.js"></script>

<script type="text/javascript">
$(function(){
    $(".Spinner").Spinner({value:1, len:3, max:999});

    $('#spinner-amount a:first').click(function() {
        var num = $('.Amount').val();
        if(num == 1) {
            $('#amountPrice').html({$goods.price});
        }
    });

    // $('.address-select-box').click(function() {
    //     $('#select-address').fadeOut(200);
    // })

});


$(document).on('click', '#wechat-pay', function(event) {
    if(!$('#address_id').val()) {
        alert('请选择收货地址');
        return false;
    }
    $('#pay-form').submit();
});
$(document).on('click', '.Increase', function(event) {
    var num = $('.Amount').val();
    $('#goods_num').val(num);
    $('#amountPrice').html(parseInt(num) * parseFloat("{$goods.price}"));
});
$(document).on('click', '.Decrease', function(event) {
    var num = $('.Amount').val();
    $('#goods_num').val(num);
    $('#amountPrice').html(parseInt(num) * parseFloat("{$goods.price}"));
});

</script>
{/block}
